#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;
using ull = unsigned long long;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 3e5 + 10;

mt19937 rnd(19260817);

int a[N],n,ans;
ull v[N],s[N],sv[N];

void calc(int pos) {
	for(int j = pos - 1,mx = 1;j >= 1 && a[j] != 1;j--) mx = max(mx,a[j]) , ans += (s[j + mx - 1] ^ s[j - 1]) == sv[mx];
	for(int j = pos + 1,mx = 1;j <= n && a[j] != 1;j++) mx = max(mx,a[j]) , ans += (s[j] ^ s[j - mx]) == sv[mx];
	ans++;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; for(int i = 1;i <= n;i++) a[i] = in,v[i] = (ull) rnd() * rnd(),sv[i] = sv[i - 1] ^ v[i];
	for(int i = 1;i <= n;i++) s[i] = s[i - 1] ^ v[a[i]];
	for(int i = 1;i <= n;i++) if(a[i] == 1) calc(i);
	printf("%d\n",ans);
	return 0;
}
